<?php
namespace app\modules\developer\models;
use common\component\tool\Tool;
use app\models\Basic;

use Yii;

class AppPrice extends Basic
{    
    public static function tableName()
    {
        return '{{%app_price}}';
    }

    public function rules()
    {
        return [
            ['app_info_id', 'default', 'value' => 0],
            ['app_info_id', 'integer', 'message' => 'app_info_id必须为数字，或数字字符串', 
                            'min'=>0, 'tooSmall' => 'app_info_id最小存储0', 
                            'max'=>65535, 'tooBig' => 'app_info_id最大存储65535'],
            ['year', 'default', 'value' => 0],
            ['year', 'integer', 'message' => 'year必须为数字，或数字字符串', 
                     'min'=>1, 'tooSmall' => 'year最小存储1', 
                     'max'=>99, 'tooBig' => 'year最大存储99'],
            ['price', 'default', 'value' => 0],
            ['price', 'integer', 'message' => 'price必须为数字，或数字字符串', 
                      'min'=>0, 'tooSmall' => 'price最小存储0', 
                      'max'=>65535, 'tooBig' => 'price最大存储65535'],
        ];
    }


    /*添加*/
    public function addAppPrice($data, $app_info_id)
    {
        $res = true;
        foreach($data as $k => $v){
            $newDate['AppPrice']['app_info_id'] = $app_info_id;
            $newDate['AppPrice']['year'] = $v['year'];
            $newDate['AppPrice']['price'] = $v['price'];

            $appPrice = new AppPrice;
            if($appPrice->load($newDate) and $appPrice->validate()){
                if(!$appPrice->save(false)){
                    $res = false;
                }
            }
        }
        return $res;
    }

    
}